package com.codeanalysissys.backend.controller;

import com.codeanalysissys.backend.service.frame.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/test")
@RestController
public class TestController {
    String[] testFiles = {"F:\\jsonltest\\java_train_0.jsonl", "F:\\jsonltest\\merge_train.jsonl"};
    int coreCount = Runtime.getRuntime().availableProcessors();
    int[] threadCounts = {coreCount, coreCount + 1, coreCount * 2, coreCount * 2 + 1};

    @Autowired
    private FileService fileService;

    // 测试单线程
    @GetMapping("/single-thread")
    public long singleThread(@RequestParam Integer fileChoice) {
        return fileService.testSingleThread(testFiles[fileChoice]);
    }

    // 多线程测试接口
    @GetMapping("/multi-threads")
    public long multiThreads(@RequestParam Integer fileChoice, @RequestParam Integer threadCountChoice) {
        return fileService.testMultiThreads(testFiles[fileChoice], threadCounts[threadCountChoice - 1]);
    }
}
